﻿@{
    ViewBag.Title = "项目管理";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
    var IsAdmin = Convert.ToBoolean(Session["IsAdmin"]);
}

<div class="main layui-clear">
    <div class="wrap">
        <div class="layui-form layui-form-pane">
            <fieldset class="layui-elem-field">
                <legend>检索条件</legend>
                <div class="layui-field-box">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">部门:</label>
                            <div class="layui-input-block">
                                <select id="Depart" name="Depart">
                                    <option value="">请选择</option>
                                    <option value="1">一部</option>
                                    <option value="2">二部</option>
                                    <option value="3">三部</option>
                                    <option value="4">四部</option>
                                    <option value="5">五部</option>
                                    <option value="6">六部</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">项目名称</label>
                            <div class="layui-input-block">
                                <select id="ProjectName" name="ProjectName">
                                    <option value="">请选择</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item" style="float:right">
                        <a href="#" class="layui-btn layui-btn-normal" id="btnSearch">
                            <i class="layui-icon layui-icon-search"></i>检索
                        </a>
                        @if (IsAdmin)
                        {
                            <a href="@Url.Action("Add","Project")" class="layui-btn layui-btn-normal">
                                <i class="layui-icon layui-icon-add-circle"></i> 添加工程
                            </a>
                        }
                    </div>
                </div>
            </fieldset>
        </div>
        <table id="project" lay-filter="project"></table>
        <script type="text/html" id="toolbarDemo">
            <b>项目一览</b>
        </script>
        <script type="text/html" id="proNameTpl">
            <a href="#" class="layui-table-link" lay-event="proName">{{d.Name || ''}}</a>
        </script>
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</a>
            @if (IsAdmin)
            {
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            }
        </script>
    </div>
    <!--分页容器-->
    <div style="text-align: center" id="paged">
    </div>
</div>
@section scripts{
    <script>
        layui.use(['jquery', 'table'], function () {
            var $ = layui.jquery;
            var table = layui.table;
         
            table.render({
                elem: '#project'
                , height: 500
                , title: '用户数据表'
                , data :[]
                , page: {

                }
                , autoSort: false
                , toolbar: '#toolbarDemo'
                , defaultToolbar: ['filter', 'exports', 'print']
                , cols: [[
                    { type: 'numbers' }
                    , { field: 'Name', title: '项目名称', width: 120, templet: '#proNameTpl'}                    
                    , { field: 'DepartName', title: '所属部门', width: 100}
                    , { field: 'ProjectKindName', title: '项目分类', width: 100 }
                    , { field: 'BefLang', title: '移行前语言', width: 110 }
                    , { field: 'AftLang', title: '移行后语言', width: 110 }
                    , { field: 'BefDB', title: '移行前DB', width: 110 }
                    , { field: 'AftDB', title: '移行后DB', width: 110 }
                    , { field: 'EndDate', title: '项目纳期', width: 120 }
                    , { title: '操作', toolbar: '#barDemo', width: 120 }
                ]]
            });

            //监听行工具事件
            table.on('tool(project)', function (obj) {
                var data = obj.data;
                if (obj.event === 'edit' || obj.event === 'proName') {                   
                    redirect('Project', 'Detail', data.Id);
                } else if (obj.event === 'del') {
                    layer.confirm('确定要删除该行数据吗？', function (index) {
                        $.ajax({
                            url: '/Project/DelProject?pid=' + data.Id,
                            type: 'post',
                            contentType: false,
                            processData: false,
                            dataType: "json",
                            success: function (res) {
                                if (res.status == 0) {
                                    layer.msg("删除成功", { icon: 1 });
                                    obj.del();
                                    layer.close(index);
                                } else if (res.status == 1) {
                                    layer.msg(res.msg, { icon: 5 });
                                }
                            }
                            , error: function () {
                                layer.msg("请求异常", { icon: 5 });
                            }
                        });       
                    });
                }
            });

            $("#btnSearch").click(function () {
                var Depart = $("#Depart").val();
                var name = $("#ProjectName").val();
                table.reload('project', {
                    url: '/Project/DataList?Depart=' + Depart + '&name=' + name
                    ,page: { curr: 1 }
                });
            });
            
        });
    </script>
}
